import { screen } from '../mutation-types'
import * as api from 'api/screen'

const state = {
  tagInfos: [],
  truckNums: [],
  truckList: []
}

const actions = {
  getTagsInfo ({ commit }) {
    api.getTagsInfo().then((data) => {
      commit(screen.GETTAGINFOS, data)
    })
  },
  getTruckNums ({ commit }, parmas) {
    api.getTruckNums(parmas).then((data) => {
      commit(screen.GETTRUCKNUMS, data)
    })
  },
  getTruckList ({ commit }, parmas) {
    return new Promise((resolve, reject) => {
      api.getTruckList(parmas).then((data) => {
        resolve(data)
      }).catch((err) => {
        reject(err)
      })
    })
  }
}

const mutations = {
  [screen.GETTAGINFOS] (state, data) {
    state.tagInfos = data
  },
  [screen.GETTRUCKNUMS] (state, data) {
    state.truckNums = data.result
  }
}

const getters = {
  tagInfos: state => state.tagInfos,
  truckNums: state => state.truckNums
}

export default {
  namespaced: true,
  state,
  actions,
  getters,
  mutations
}
